package com.navcoo.todolist.controller;

import cn.hutool.core.util.BooleanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.navcoo.todolist.pojo.dao.TodoDataDAO;
import com.navcoo.todolist.pojo.dto.CreateTodoDataDTO;
import com.navcoo.todolist.pojo.dto.DeleteTodoDataDTO;
import com.navcoo.todolist.pojo.dto.SearchTodoDatasDTO;
import com.navcoo.todolist.pojo.dto.UpdateTodoDataDTO;
import com.navcoo.todolist.response.Result;
import com.navcoo.todolist.response.exception.ResultStatus;
import com.navcoo.todolist.service.CreateTodoData;
import com.navcoo.todolist.service.DeleteTodoData;
import com.navcoo.todolist.service.SearchTodoDatas;
import com.navcoo.todolist.service.UpdateTodoData;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Todo控制器
 *
 * @author Navcoo
 * @date 2024-02-11
 */
@Slf4j
@RestController
@RequestMapping("/todo")
@RequiredArgsConstructor
public class TodoController {

    private final CreateTodoData createTodoData;

    private final SearchTodoDatas searchTodoDatas;

    private final DeleteTodoData deleteTodoData;

    private final UpdateTodoData updateTodoData;

    @RequestMapping("/createTodoData")
    public Result<Object> createTodoData(@RequestBody @Validated CreateTodoDataDTO createTodoDataDTO) throws Exception {
        log.info("创建待办事项数据，参数：{}", createTodoDataDTO);
        return Result.success("创建待办事项数据成功", createTodoData.createTodoData(createTodoDataDTO.getTitle()));
    }

    @RequestMapping("/searchTodoDatas")
    public Result<Object> searchTodoDatas(@RequestBody @Validated SearchTodoDatasDTO searchTodoDatasDTO) throws Exception {
        log.info("查询待办事项数据，参数：{}", searchTodoDatasDTO);

        return Result.success(searchTodoDatas.searchTodoDatas(
                searchTodoDatasDTO.getPageSize(),
                searchTodoDatasDTO.getCurrentPage(),
                searchTodoDatasDTO.getIsDone())
        );
    }

    @RequestMapping("/deleteTodoData")
    public Result<Object> deleteTodoData(@RequestBody @Validated DeleteTodoDataDTO deleteTodoDataDTO) throws Exception {
        log.info("删除待办事项数据，参数：{}", deleteTodoDataDTO);
        return Result.success("删除待办事项数据成功", deleteTodoData.deleteTodoData(deleteTodoDataDTO.getInstId()));
    }

    @RequestMapping("/updateTodoData")
    public Result<Object> updateTodoData(@RequestBody @Validated UpdateTodoDataDTO updateTodoDataDTO) throws Exception {
        log.info("更新待办事项数据，参数：{}", updateTodoDataDTO);
        return Result.success("更新待办事项数据成功", updateTodoData.updateTodoData(updateTodoDataDTO.getInstId(),updateTodoDataDTO.getIsDone()));
    }
}
